libarchive: Handle `archive_entry_symlink()` returning NULL
authorColin Walters <walters@verbum.org>
Mon, 4 Apr 2022 14:25:35 +0000 (10:25 -0400)
committerColin Walters <walters@verbum.org>
Mon, 4 Apr 2022 14:25:35 +0000 (10:25 -0400)
The `archive_entry_symlink()` API can definitely return `NULL`,
reading through the libarchive sources.

I hit this in the wild when using old ostree-ext to try to unpack
a chunked archive.

I didn't try to characterize this more, and sorry no unit test right
now.

src/libostree/ostree-repo-libarchive.c

index 679aa44da964cdecda8f2300dbb43f88b5ff3263..631c6d4b8f58dd28b806117cae893b914ac519c9 100644 (file)
@@ -146,8 +146,12 @@ file_info_from_archive_entry (struct archive_entry *entry)
 
   g_autoptr(GFileInfo) info = _ostree_stbuf_to_gfileinfo (&stbuf);
   if (S_ISLNK (stbuf.st_mode))
-    g_file_info_set_attribute_byte_string (info, "standard::symlink-target",
-                                           archive_entry_symlink (entry));
+    {
+      const char *target = archive_entry_symlink (entry);
+      if (target != NULL)
+        g_file_info_set_attribute_byte_string (info, "standard::symlink-target",
+                                               target);
+    }
 
   return g_steal_pointer (&info);
 }